package krillr.Util;

/**
 * Vector2d - 2D vector class based on the work by Hanji
 * 
 * @author Aaron M. Krill
 * @version 0.1
 */
public class Vector2d
{
    double x, y;
    
    public Vector2d()
    {
        x = 1;
        y = 1;
    }
    
    public Vector2d(double rads)
    {
        setDirection(rads);
    }
    
    public Vector2d(double rads, double sM)
    {
        setDirection(rads);
        setMagnitude(sM);
    }
    
    public double getX() { return x; }
    
    public double getY() { return y; }
    
    public void setX(double sX) { x = sX; }
    
    public void setY(double sY) { y = sY; }
    
    public double getMagnitude() { return Math.sqrt(Math.pow(x,2) + Math.pow(y,2)); }
    
    public double getDirection() { return Math.atan2(x,y); }
    
    public void setMagnitude(double sMagnitude) {
        double theta  = getDirection();
        x = sMagnitude * Math.sin(theta);
        y = sMagnitude * Math.cos(theta);
    }
    
    public void setDirection(double sDirection)
    {
        double magnitude = getMagnitude();
        x = magnitude * Math.sin(sDirection);
        y = magnitude * Math.cos(sDirection);
    }
    
    public Vector2d Normalise() { return new Vector2d(Math.sin(getDirection()), Math.cos(getDirection())); }
    
    public Vector2d Add(Vector2d sVector2d) { return new Vector2d(x + sVector2d.x, y + sVector2d.y); }
    
    public Vector2d Subtract(Vector2d sVector2d) { return new Vector2d( x- sVector2d.x, y - sVector2d.y); }
    
    public Vector2d Inverse() { return new Vector2d(-x,-y); }
    
    public double Dot(Vector2d sVector2d) { return Math.sqrt(x * sVector2d.x + y * sVector2d.y); }
    
    public Vector2d Multiply(double sScalar) { return new Vector2d(x * sScalar, y * sScalar); }
    
    public Point2d translateToPoint() { return new Point2d(x,y); }
    
    public Point2d translateToPoint(Point2d source) { return new Point2d(source.x + x, source.y + y); }    
}